import { createStore } from 'vuex'

import { getMusicLyric } from '@/request/api/item'

import { getPhoneLogin } from '@/request/api/home'

export default createStore({
  state: {
    playList: [{
      al: {
        id: 126199461,
        name: "All You Need Is Me",
        pic: 109951165904755220,
        picUrl: "http://p4.music.126.net/nxbXqlt5UR48oLhWT6-VnQ==/109951165904755215.jpg",
        pic_str: "109951165904755215",
      },
      id: 1838510188,
      name: "王成斌",
      ar: [{ name: "忘纯白" }]
    }],
    playListIndex: 0,// 下标
    isbtnShow: true,// 暂停按钮的显示
    detailShow: false,// 歌曲详情页
    lyricList: {},// 歌词
    currentTime: 0,// 当前时间
    duration: 0,// 歌曲时长
    isLogin: false,// 判断是否登录
    isFooterMusic: true,// 判断底部组件是否显示
    token: '',
    user: {}
  },
  getters: {
  },
  mutations: {
    updateIsbtnShow(state, value) {
      state.isbtnShow = value
    },
    pushPlayList(state, value) {
      state.playList.push(value)
    },
    updatePlayList(state, value) {
      state.playList = value
      console.log(state.playList)
    },
    updatePlayListIndex(state, value) {
      state.playListIndex = value
    },
    updateDetailShow(state) {
      state.detailShow = !state.detailShow
    },
    updateLyricList: function (state, value) {
      state.lyricList = value
    },
    updateCurrentTime(state, value) {
      state.currentTime = value
    },
    updateDurationTime(state, value) {
      state.duration = value
    },
    updateIsLogin(state, value) {
      state.isLogin = true
    },
    updataToken(state, value) {
      state.token = value
      localStorage.setItem('token', state.token)
    },
    updataUser(state, value) {
      state.user = value
    }
  },
  actions: {
    async getLyric(context, value) {
      let res = await getMusicLyric(value)
      console.log(res)
      context.commit("updateLyricList", res.data.lrc)
    },
    async getLogin(context, value) {
      let res = await getPhoneLogin(value)
      // console.log(res)
      return res

    }
  },
  modules: {
  }
})
